#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define vec vector<int>

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);return x*sgn;}

const int N = 2510;
const db inf = 1e14;

int k,n,s[N],p[N],fa[N],siz[N];
db f[N][N],mid,a[N],tmp[N];

bool check(){
	for(int i = 1;i <= n;i++) a[i] = p[i] - s[i] * mid;
	for(int i = 0;i <= n;i++){
		for(int j = 1;j <= k;j++) f[i][j] = -inf;
		f[i][0] = 0; siz[i] = 1;
	}
	for(int x = n;x >= 1;x--){
		int y = fa[x]; for(int j = siz[x];j >= 1;j--) f[x][j] = f[x][j-1] + a[x];
		for(int j = 1;j <= min(siz[x] + siz[y],k);j++) tmp[j] = -inf;
		for(int j = 1;j <= siz[x];j++)
			for(int d = 0;d < siz[y] && d + j <= k;d++)
				tmp[j + d] = max(tmp[j + d],f[x][j] + f[y][d]);
		siz[y] += siz[x]; siz[y] = min(siz[y],k);
		for(int j = 1;j <= siz[y];j++) f[y][j] = max(f[y][j],tmp[j]);
	}
	return f[0][k] >= 0;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	k = in,n = in;
	for(int i = 1;i <= n;i++) s[i] = in,p[i] = in,fa[i] = in;
	db l = 0,r = 1000;
	for(int i = 1;i <= 30;i++){mid = (l + r) / 2; if(check()) l = mid;else r = mid;}
	printf("%.3lf\n",mid);
	return 0;
}
